package behavior.responsechain;

/**
 * Created by lie on 2017/11/3.
 * 领导链
 */
public abstract class LeaderChain {

    protected LeaderChain nextLeader;

    /**
     * 链式的处理请求
     * @param money
     */
    protected void handleRequest(int money){
        if (money < moneyLimit()) {
            handle(money);
        }else {
            //交给下一个节点处理
            if (nextLeader != null) {
                nextLeader.handleRequest(money);
            }else
                System.out.println("无人有权限处理这笔钱 = " + money + "元");
        }
    }

    /**
     * 节点处理请求
     * @param money
     */
    protected abstract void handle(int money);

    /**
     * 每一个节点的限制
     * @return
     */
    protected abstract int moneyLimit();
}
